<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>组件管理系统</title>
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <meta http-equiv="Cache-Control" content="no-siteapp"/>

    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon"/>
    <link rel="stylesheet" href="./css/font.css">
    <link rel="stylesheet" href="./css/xadmin.css">
    <script type="text/javascript" src="./lib/vue/jquery.min.js"></script>
    <script src="./lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="./js/xadmin.js"></script>
    <script type="text/javascript" src="./js/cookies.js"></script>
    <script type="text/javascript" src="./js/global.js"></script>

</head>
<body class="login-bg">

<div class="login layui-anim layui-anim-up">
    <div class="message">平台组件管理系统-登录 V1.0</div>
    <div id="darkbannerwrap"></div>

    <form method="post" class="layui-form">
        <input id="username" name="username" placeholder="用户名" type="text" lay-verify="required" class="layui-input">
        <hr class="hr15">
        <input name="password" lay-verify="required" placeholder="密码" type="password" class="layui-input">
        <hr class="hr15">
        <div class="layui-form-item">
            <label class="layui-form-label" style="padding: 5px;text-align: left;width: 50px">记住我</label>
            <div class="layui-input-block" style="margin-left: 0px">
                <input id="remember" checked type="checkbox" name="switch" lay-text="开|关" lay-skin="switch"
                       lay-filter="remember">
            </div>
        </div>
        <input value="登录" lay-submit lay-filter="login" style="width:100%;" type="submit">
        <hr class="hr20">
    </form>
    <div>
        <a href="javascript:;" onclick="x_admin_show('注册企业账号','register.html',800,550,false)">注册企业账号</a>
    </div>
</div>

<script>
    $(function () {
        var username = getCookie('username')
        var remember = getCookie('remember')
        if (remember && remember == '1' && username && username != '') {
            $("#username").val(username)
            $("#remember").attr("checked", "")

        } else {
            $("#remember").removeAttr("checked")
        }
        layui.use('form', function () {
            var form = layui.form;
            form.on('switch(remember)', function (data) {
                //记住用户名
                if (data.elem.checked) {
                    setCookie('remember', '1')
                } else {
                    setCookie('remember', '0')
                }
            });
            //监听提交
            form.on('submit(login)', function (data) {
                $.post(_hostUrl + '/login', data.field, function (res) {
                    if (res.responseCode != 200) {
                        layer.msg(res.responseMsg, {time: 2000});
                        return
                    }
                    setCookie('login', 'true')
                    setCookie('userId', res.data.user.id)
                    setCookie('username', res.data.user.username)
                    setCookie('userType', res.data.user.managerFlag)
                    setCookie('componentIds', res.data.managerInfo.componentIds)
                    setCookie('companyName', res.data.managerInfo.companyName)
                    setCookie('companyId', res.data.managerInfo.companyId)
                    setCookie('sysName', res.data.managerInfo.sysName)
                    setCookie('sysId', res.data.managerInfo.sysId)
                    layer.msg('登录成功', {icon: 1, time: 1000}, function () {
                        location.href = 'index.html'
                    });
                }, 'json');
                return false;
            });
        });
    })
</script>
</body>
</html>